home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / om301.zip / BUTTONS.PAS < prev    next >
Pascal/Delphi Source File  |  1992-01-09  |  7KB  |  227 lines

  1. {Buttons - Extensions to ObjectWindows Copyright (C) Doug Overmyer 7/1/91}
  2. unit Buttons;
  3. {************************  Interface    ***********************}
  4. interface
  5. uses WinTypes, WinProcs, WinDos, Strings, WObjects;
  6. type
  7. PODButton = ^TODButton;
  8. TODButton = object(TButton)
  9.     HBmp :HBitmap;
  10.   State:Integer;
  11.   constructor    Init(AParent:PWindowsObject; AnID:Integer;ATitle:PChar;
  12.       X,Y,W,H:Integer;IsDefault:Boolean;BMP:PChar);
  13.   destructor    Done;virtual;
  14.   procedure    DrawItem(var Msg:TMessage);virtual;
  15. end;
  16. type
  17. PODRButton = ^TODRButton;
  18. TODRButton = object(TRadioButton)
  19.     HBmp :HBitmap;
  20.   State:Integer;
  21.   constructor    Init(AParent:PWindowsObject; AnID:Integer;ATitle:PChar;
  22.       X,Y,W,H:Integer;AGroup:PGroupBox;BMP:PChar);
  23.   destructor    Done;virtual;
  24.   procedure    DrawItem(var Msg:TMessage);virtual;
  25. end;
  26.  
  27. PODGroupBox = ^TODGroupBox;
  28. TODGroupbox = object(TGroupBox)
  29.     OldBNR:PODRButton;
  30.   OldBNRID:Integer;
  31.   constructor Init(AParent:PWindowsObject;AnID:Integer;AText:PChar;
  32.       X,Y,W,H:Integer);
  33.     procedure SelectionChanged(ControlID:Integer);virtual;
  34. end;
  35.  
  36. {************************  Implementation      **********************}
  37. implementation
  38. const
  39.     sr_Recessed = 1;
  40.   sr_Raised   = 0;
  41. {************************  DrawHiLites   ****************************}
  42. function DrawHilites(PaintDC:hDC;X1,Y1,X2,Y2,LW,State:Integer):Boolean;
  43. var
  44.   LPts:Array[0..2] of TPoint;
  45.   RPts:Array[0..2] of TPoint;
  46.   Pen1:HPen;
  47.   Pen2:HPen;
  48.   OldBrush :HBrush;
  49.   OldPen:HPen;
  50.   OldBkMode:Integer;
  51.   DRect:TRect;
  52.   Ofs,W,H:Integer;
  53. begin
  54.   Ofs := 0;
  55.     LPts[0].x := X1+Ofs;   LPts[0].y := Y2-Ofs;
  56.     LPts[1].x := X1+Ofs;   LPts[1].y := Y1+Ofs;
  57.   LPts[2].x := X2-Ofs;   LPts[2].y := Y1+Ofs;
  58.   RPts[0].x := X1+Ofs;   RPts[0].y := Y2-Ofs;
  59.     RPts[1].x := X2-Ofs;   RPts[1].y := Y2-Ofs;
  60.     RPts[2].x := X2-Ofs;   RPts[2].y := Y1+Ofs;
  61.  
  62.      Pen1 := CreatePen(ps_Solid,2,$00000000);  {Draw a surrounding blk frame}
  63.   OldPen := SelectObject(PaintDC,Pen1);
  64.   PolyLine(PaintDC,LPts,3);
  65.   PolyLine(PaintDC,RPts,3);
  66.   SelectObject(PaintDC,OldPen);
  67.   DeleteObject(Pen1);    
  68.  
  69.   If State = sr_Recessed then
  70.       Ofs := lw
  71.   else
  72.       Ofs := 0;
  73.   
  74.     LPts[0].x := X1+Ofs;   LPts[0].y := Y2-Ofs;
  75.     LPts[1].x := X1+Ofs;   LPts[1].y := Y1+Ofs;
  76.   LPts[2].x := X2-Ofs;   LPts[2].y := Y1+Ofs;
  77.   RPts[0].x := X1+Ofs;   RPts[0].y := Y2-Ofs;
  78.     RPts[1].x := X2-Ofs;   RPts[1].y := Y2-Ofs;
  79.     RPts[2].x := X2-Ofs;   RPts[2].y := Y1+Ofs;
  80.   if State = sr_Raised then
  81.       begin
  82.         Pen1 := CreatePen(ps_Solid,LW,$00FFFFFF);
  83.     Pen2 := CreatePen(ps_Solid,LW,$00000000);
  84.     end
  85.   else
  86.       begin
  87.       Pen1 := CreatePen(ps_Solid,LW,$00000000);
  88.         Pen2 := CreatePen(ps_Solid,LW,$00FFFFFF);
  89.     end;
  90.  
  91.   OldPen := SelectObject(PaintDC,Pen1);   {Draw the highlights}
  92.   PolyLine(PaintDC,LPts,3);
  93.   SelectObject(PaintDC,Pen2);
  94.   DeleteObject(Pen1);
  95.  
  96.   PolyLine(PaintDC,RPts,3);
  97.   SelectObject(PaintDC,OldPen);
  98.   DeleteObject(Pen2);
  99. end;
  100.  
  101.  
  102. constructor    TODButton.Init(AParent:PWindowsObject; AnID:Integer;ATitle:PChar;
  103.        X,Y,W,H:Integer;IsDefault:Boolean;BMP:PChar);
  104. begin
  105.     TButton.Init(AParent,AnID,ATitle,X,Y,W,H,IsDefault);
  106.   Attr.Style := Attr.Style or bs_OwnerDraw;
  107.   HBmp := LoadBitmap(HInstance,BMP);
  108. end;
  109.  
  110. destructor    TODButton.Done;
  111. begin
  112.     DeleteObject(HBmp);
  113.     TButton.Done;
  114. end;
  115.  
  116. procedure    TODButton.DrawItem(var Msg:TMessage);
  117. var
  118.     TheDC,MemDC:HDc;
  119.     ThePen,Pen1,Pen2,OldPen:HPen;
  120.   TheBrush,OldBrush:HBrush;
  121.   OldBitMap:HBitMap;
  122.   LPts,RPts:Array[0..2] of TPoint;
  123.   PDIS :^TDrawItemStruct;
  124.   X,Y,W,H:Integer;
  125.   PenWidth,OffSet:Integer;
  126.   DBU:LongRec;
  127. begin
  128.     LongInt(DBU) := GetDialogBaseUnits;
  129.     PDIS := Pointer(Msg.lParam);
  130.   if PDIS^.itemAction = oda_Focus then Exit;
  131.     if ((PDIS^.itemAction and oda_Select ) > 0) and
  132.       ((PDIS^.itemState and ods_Selected) > 0) then
  133.     State := sr_Recessed else State := sr_Raised;        {1 = depressed}
  134.   X := PDIS^.rcItem.left;    Y := PDIS^.rcItem.top;
  135.   W := PDIS^.rcItem.right-PDIS^.rcItem.left;
  136.   H := PDIS^.rcItem.bottom-PDIS^.rcItem.top;
  137.   OffSet := Round((PDIS^.rcItem.bottom-PDIS^.rcItem.top) / (DBU.lo * 4));               {scale highlites based on size}
  138.   PenWidth := OffSet;
  139.   MemDC := CreateCompatibleDC(PDIS^.HDC);
  140.   OldBitMap := SelectObject(MemDC,HBMP);
  141.   if State = sr_Raised then BitBlt(PDIS^.HDC,X,Y,W,H, MemDC,0,0,SrcCopy)
  142.       else BitBlt(PDIS^.HDC,X+OffSet,Y+OffSet,W,H, MemDC,0,0,SrcCopy);
  143.   SelectObject(MemDC,OldBitMap);
  144.   DeleteDC(MemDC);
  145.   DrawHiLites(PDIS^.hDC,X,Y,PDIS^.rcItem.Right,PDIS^.rcitem.Bottom,OffSet,State)
  146. end;
  147. {********************* TODRButton  *****************************}
  148. constructor    TODRButton.Init(AParent:PWindowsObject; AnID:Integer;ATitle:PChar;
  149.        X,Y,W,H:Integer;AGroup:PGroupBox;BMP:PChar);
  150. begin
  151.     TRadioButton.Init(AParent,AnID,ATitle,X,Y,W,H,AGroup);
  152.   Attr.Style := Attr.Style or bs_OwnerDraw;
  153.   HBmp := LoadBitmap(HInstance,BMP);
  154.   State := sr_Raised;
  155. end;
  156.  
  157. destructor    TODRButton.Done;
  158. begin
  159.     DeleteObject(HBmp);
  160.     TRadioButton.Done;
  161. end;
  162.  
  163. procedure    TODRButton.DrawItem(var Msg:TMessage);
  164. var
  165.     TheDC,MemDC:HDc;
  166.   OldBitMap:HBitMap;
  167.   Offset:Integer;
  168.   LPts,RPts:Array[0..2] of TPoint;
  169.   PDIS :^TDrawItemStruct;
  170.   X,Y,W,H:Integer;
  171.   DBU:LongRec;
  172.   GKS:Integer;
  173. begin
  174.     LongInt(DBU) := GetDialogBaseUnits;
  175.     PDIS := Pointer(Msg.lParam);
  176.   GKS := GetKeyState(vk_LButton);
  177.   If IsIconic(hWindow) then Exit;
  178.   if (PDIS^.itemAction = 1)     then
  179.      State := State
  180.   else if (PDIS^.itemAction = 2) and (PDIS^.ItemState = 17)
  181.       then State := sr_Recessed
  182.   else if (PDIS^.itemAction = 2) and (PDIS^.ItemState = 16) and (GKS < 0)
  183.       then State := sr_Raised
  184.   else Exit;
  185.   X := PDIS^.rcItem.left;    Y := PDIS^.rcItem.top;
  186.   W := PDIS^.rcItem.right-PDIS^.rcItem.left;
  187.   H := PDIS^.rcItem.bottom-PDIS^.rcItem.top;
  188.   OffSet := Round((PDIS^.rcItem.bottom-PDIS^.rcItem.top) / (DBU.lo * 4));               {scale highlites based on size}
  189.   MemDC := CreateCompatibleDC(PDIS^.HDC);
  190.   OldBitMap := SelectObject(MemDC,HBMP);
  191.   if State = 0 then BitBlt(PDIS^.HDC,X,Y,W,H, MemDC,0,0,SrcCopy)
  192.       else BitBlt(PDIS^.HDC,X+OffSet,Y+OffSet,W,H, MemDC,0,0,SrcCopy);
  193.   SelectObject(MemDC,OldBitMap);
  194.   DeleteDC(MemDC);
  195.   DrawHiLites(PDIS^.hDC,X,Y,PDIS^.rcItem.Right,PDIS^.rcitem.Bottom,OffSet,State)
  196. end;
  197. {******************  TODGroupBox   ******************************}
  198. constructor TODGroupBox.Init(AParent:PWindowsObject;AnID:Integer;AText:PChar;
  199.       X,Y,W,H:Integer);
  200. begin
  201.     TGroupBox.Init(AParent,AnId,AText,X,Y,W,H);
  202.   Attr.Style := Attr.Style and not ws_Visible;
  203.   OldBNR := nil;
  204.   OldBNRID := 0;
  205. end;
  206.  
  207. procedure TODGroupBox.SelectionChanged(Controlid:Integer);
  208. begin
  209.     TGroupBox.SelectionChanged(Controlid);
  210.   if ControlID = OldBNRID then
  211.       Exit;
  212.     If OldBNR = nil then
  213.       begin
  214.       OldBNR := PODRButton(Parent^.ChildWithID(ControlID));
  215.     OldBNRID := ControlID;
  216.     end
  217.   else
  218.       begin
  219.     OldBNR^.State := sr_Raised;
  220.     InvalidateRect(OldBNR^.HWindow,nil,True);
  221.     OldBNR := PODRButton(Parent^.ChildWithID(Controlid));
  222.     OldBNRID := ControlID;
  223.     end;
  224. end;
  225.  
  226. end.
  227.